$(function () {
    let markid = getUrlString('markid');
    let page = -1,totalSize = 0;
    let mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#redList').empty();//清空容器
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                redList(page);
            }
        }
    });

    function redList (page) {
        let data = {
            'markid':markid,
            'page':page
        };
        getData('post','/niu/apiv4/niu_hongbao.php',data,function (data) {
            console.log(data);
            let append = '';
            $('#redNum').html(data.num);
            $('#cupNum,.cupTypeNum').html(data.num_coupon+'张');
            $(data.info).each(function () {
                let syNum = Number(this.money4) - Number(this.usedmoney)
                append += '<li>' +
                    '                    <div>'+this.intro+'</div>' +
                    '                    <div class="time">有效期至'+this.outtime+'</div>' +
                    '                    <div class="info">仅限金币扭蛋机消费使用。</div>' +
                    '                    <div class="num">' +
                    '                        <img src="../../res/img/common/redPacket.png" alt="">' +
                    '                        <span>'+this.money4+' / '+syNum+'</span>' +
                    '                    </div>' +
                    '                </li>'
            });
            $('#redList').append(append);
            //总条数
            totalSize = totalSize + 10;
            if (totalSize > data.datacount)
                mRefresh.endUpLoading(true);
            else{
                mRefresh.endUpLoading(false);
            }
        })
    }
});
